package com.cjm.bridge;

import java.lang.reflect.Method;
import java.util.Arrays;

public class TestMain {
    public static void main(String[] args) {
        Son son = new Son();
        Method[] declaredMethods = son.getClass().getDeclaredMethods();
        for (int j = 0; j < declaredMethods.length; j++) {
            Method declaredMethod = declaredMethods[j];
            String name = declaredMethod.getName();
            Class<?> returnType = declaredMethod.getReturnType();
            Class<?> declaringClass = declaredMethod.getDeclaringClass();
            boolean bridge = declaredMethod.isBridge();
            if (bridge) {
                System.err.println("is bridge method, "+"method:" + name + ";returnType:" + returnType.getSimpleName() + ";declar class:" + declaringClass.getSimpleName());
            } else {
                System.err.println("method:" + name + ";returnType:" + returnType.getSimpleName() + ";declar class:" + declaringClass.getSimpleName());
            }
        }
    }
    private static void method2() {
        MyNode mn = new MyNode(5);
        Method[] declaredMethods = mn.getClass().getDeclaredMethods();
        for (int i = 0; i < declaredMethods.length; i++) {
            Method declaredMethod = declaredMethods[i];
            String methodName = declaredMethod.getName();
            Class<?>[] parameterTypes = declaredMethod.getParameterTypes();
            Class<?> declaringClass = declaredMethod.getDeclaringClass();
            boolean bridge = declaredMethod.isBridge();
            System.out.print("第" + (i + 1) + "个方法名称：" + methodName + "，参数类型：" + Arrays.toString(parameterTypes) + "  ");
            System.out.print(bridge ? " 是桥接方法" : " 不是桥接方法");
            System.out.println("  这个方法是在" + declaringClass.getSimpleName() + "上申明的");
        }
    }

    private static void method1() {
        Son son = new Son();
        Method[] declaredMethods = son.getClass().getDeclaredMethods();
        for (int j = 0; j < declaredMethods.length; j++) {
            Method declaredMethod = declaredMethods[j];
            String name = declaredMethod.getName();
            Class<?> returnType = declaredMethod.getReturnType();
            Class<?> declaringClass = declaredMethod.getDeclaringClass();
            boolean bridge = declaredMethod.isBridge();
            if (bridge) {
                System.err.println("is bridge method, "+"method:" + name + ";returnType:" + returnType.getSimpleName() + ";declar class:" + declaringClass.getSimpleName());
            } else {
                System.err.println("method:" + name + ";returnType:" + returnType.getSimpleName() + ";declar class:" + declaringClass.getSimpleName());
            }
        }
    }
}
